package com.chs.recoginition.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chs.recoginition.mapper.CommentsMapper;
import com.chs.recoginition.pojo.Comments;
import com.chs.recoginition.service.ICommentsService;
import com.chs.recoginition.vo.PageRespVo;
import com.chs.recoginition.vo.reqvo.CommentPageVo;
import com.chs.recoginition.vo.respVo.CommentRespVo;
import com.chs.recoginition.vo.respVo.UserRespVo;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 留言 服务实现类
 * </p>
 * @author CHS
 * @since 2023-04-08
 */
@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements ICommentsService {

    @Override
    public PageRespVo<CommentRespVo> findPage(CommentPageVo reqVo) {
        return baseMapper.findPage(reqVo);
    }

    @Override
    public void save(Comments reqVo, UserRespVo userRespVo) {
        reqVo.setCreatedBy(userRespVo.getUserId());
        reqVo.setCreatedTime(LocalDateTime.now());
        baseMapper.insert(reqVo);
    }

    @Override
    public void modify(Comments reqVo, UserRespVo userRespVo) {
        reqVo.setCreatedBy(userRespVo.getUserId());
        reqVo.setCreatedTime(LocalDateTime.now());
        baseMapper.updateById(reqVo);
    }

    @Override
    public void remove(String idList) {
        List<Integer> ids = Arrays.stream(idList.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        this.removeByIds(ids);
    }
}
